/*******************************************************************************************************

Figure 6: The ATE for different types of senders

*******************************************************************************************************/

*Set directory path
cd "C:\Users\tsa23\Documents\petitions\replication files"

clear all

*read in our main dataset
use dta/did_rep.dta


*Elminate contrituencies which are not part of case G
drop if ID == 45 //University of Cambridge
drop if ID == 191 //University of Oxford
keep if new == 1 | drummond == .

drop if year==1830 | year==1831 | year==1832

gen treatgroup = 0
replace treatgroup =  1 if new==1 

gen treatinter = treatperiod*treatgroup

label var type1 "Religion"
label var type2 "Citizens"
label var type3 "Societies"
label var type4 "Local government"
label var type5 "Business"
label var type6 "Transport"
label var type7 "Others"


foreach n of numlist 1/7 {
gen temptype`n' = type`n'
replace temptype`n'=0 if type`n'==.
}


gen business = temptype6 + temptype5
replace business =. if business == 0
replace business = ln(business+1)

gen religious = temptype1 
replace religious =. if religious==0
replace religious = ln(religious+1)

gen societies =  temptype3  
replace societies =. if societies==0
replace societies = ln(societies+1)

gen individuals =  temptype2
replace individuals =. if individuals==0
replace individuals = ln(individuals+1)


gen local = temptype4  
replace local =. if local==0
replace local = ln(local+1)

collapse ln_petitions local business religious societies individuals treatgroup, by(ID treatperiod treatinter)

label var treatinter "T * A" 
label var treatgroup "T" 
label var treatperiod "A" 

label var societies "societies" /*Petitions from civic groups*/
label var business "Petitions from business groups"
label var individuals "Petitions from individual citizens"
label var religious "Petitions from religious groups"
label var local "Petitions from local government bodies"

gen year = treatperiod
tsset ID year

set scheme plotplainblind
gen treatinterL0 =treatinter
label var treatinterL0 "Societies" 
xtreg societies treatinterL0  i.year, fe cluster(ID)
* this makes sure that we only use towns that got information before and after. The point estimates are the same but the stds are a bit different.
gen ok=e(sample)
egen sumok=total(ok), by(ID)
su sumok, meanonly
gen allok=(sumok==r(max))
xtreg societies treatinterL0  i.year if allok==1, fe cluster(ID)
estimates store mL0
drop ok sumok allok


gen treatinterL1 =treatinter
label var treatinterL1 "Business groups"
xtreg business treatinterL1  i.year, fe cluster(ID)
* this makes sure that we only use towns that got information before and after. The point estimates are the same but the stds are a bit different.
gen ok=e(sample)
egen sumok=total(ok), by(ID)
su sumok, meanonly
gen allok=(sumok==r(max))
xtreg business treatinterL1 i.year if allok==1, fe cluster(ID)
estimates store mL1
drop ok sumok allok


gen treatinterL2 =treatinter
label var treatinterL2 "Individuals" 
xtreg individuals treatinterL2  i.year, fe cluster(ID)
* this makes sure that we only use towns that got information before and after. The point estimates are the same but the stds are a bit different.
gen ok=e(sample)
egen sumok=total(ok), by(ID)
su sumok, meanonly
gen allok=(sumok==r(max))
xtreg individuals treatinterL2  i.year if allok==1, fe cluster(ID)
estimates store mL2
drop ok sumok allok


gen treatinterL3 =treatinter
label var treatinterL3 "Religious groups"
xtreg religious treatinterL3 i.year, fe cluster(ID)
* this makes sure that we only use towns that got information before and after. The point estimates are the same but the stds are a bit different.
gen ok=e(sample)
egen sumok=total(ok), by(ID)
su sumok, meanonly
gen allok=(sumok==r(max))
xtreg religious treatinterL3 i.year if allok==1, fe cluster(ID)
estimates store mL3
drop ok sumok allok

gen treatinterL4 =treatinter
label var treatinterL4 "Local government"
xtreg local treatinterL4 i.year, fe cluster(ID)
* this makes sure that we only use towns that got information before and after. The point estimates are the same but the stds are a bit different.
gen ok=e(sample)
egen sumok=total(ok), by(ID)
su sumok, meanonly
gen allok=(sumok==r(max))
xtreg local treatinterL4 i.year if allok==1, fe cluster(ID)
estimates store mL4
drop ok sumok allok

coefplot mL0 mL1 mL2 mL3 mL4, ///
    drop(_cons) ///
    keep(treatinterL0 treatinterL1 treatinterL2 treatinterL3 treatinterL4) ///
    ci(95) ///
    msymbol(O) mcolor(black) mlcolor(black) /// points in black
    ciopts(recast(rcap) lcolor(black) lwidth(medthin)) /// CIs in black
    xline(0, lcolor(gs8)) /// zero line in grey
    legend(off) ///
    title("")

graph export "graphs/figure6.pdf", as(pdf) name("Graph") replace



